473,432 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,432 software developers and data experts.

Can I use JS to search folder and create array from files

I would like to put all my .jpg images in a folder into an array to be
viewed. can I use JS to do this automatically. Without having to type
by hand?

Jan 9 '07 #1
8 8895
wrote on 09 jan 2007 in comp.lang.javascript:
I would like to put all my .jpg images in a folder into an array to be
viewed. can I use JS to do this automatically. Without having to type
by hand?
IS "can I use JS to do this automatically" the question?

The answer is yes, you can, but not with js in a html page on the client's
browser without compromizing web security, if your folder is on the
client's hard disk.

Yes you can, if the folder is on a server and the javascript is serverside,
probably on an ASP platform.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 9 '07 #2

mdh2...@gmail.com wrote:
I would like to put all my .jpg images in a folder into an array to be
viewed. can I use JS to do this automatically. Without having to type
by hand?
No, JS cannot access any of the files or directories it sits with on
the server. You'd have to use a server side language like PHP, Perl, or
ASP.

Jan 10 '07 #3
Benjamin said the following on 1/9/2007 10:10 PM:
mdh2...@gmail.com wrote:
>I would like to put all my .jpg images in a folder into an array to be
viewed. can I use JS to do this automatically. Without having to type
by hand?
No, JS cannot access any of the files or directories it sits with on
the server.
I don't believe that. You can't get a directory listing, easily, but you
*do* have access to any file that is in the same domain as long as the
server doesn't prohibit access. If JS couldn't access them, AJAX would
be a totally dead technology.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 10 '07 #4
Hi,

md*****@gmail.com wrote:
I would like to put all my .jpg images in a folder into an array to be
viewed. can I use JS to do this automatically. Without having to type
by hand?
You don't give enough details to answer that question. For example:

- Is the folder with the files on the client or the server?
- Do you have a possibility to add code to the server? For example
ASP.NET, PHP, ...
- Do you want the page to be refreshed when you navigate to a new folder
or not?

If the folder is on the client, the answer is no in normal web security
conditions. If you have reduced security (for example in the "file"
protocol), then you can access the client's filesystem, but that's
probably not what you want.

If the folder is on the server, then there are solutions using
JavaScript, with or without server counterpart.

Please elaborate.
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 10 '07 #5

Randy Webb wrote:
Benjamin said the following on 1/9/2007 10:10 PM:
mdh2...@gmail.com wrote:
I would like to put all my .jpg images in a folder into an array to be
viewed. can I use JS to do this automatically. Without having to type
by hand?
No, JS cannot access any of the files or directories it sits with on
the server.

I don't believe that. You can't get a directory listing, easily, but you
*do* have access to any file that is in the same domain as long as the
server doesn't prohibit access. If JS couldn't access them, AJAX would
be a totally dead technology.
These are different things. Yes, AJAX can acess files back at the
server, but it has to name them specifically. You can not scan a
directory and retrieve the listing with JS.
>
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 14 '07 #6
ASM
Benjamin a écrit :
Randy Webb wrote:
>Benjamin said the following on 1/9/2007 10:10 PM:
>>mdh2...@gmail.com wrote:
I would like to put all my .jpg images in a folder into an array to be
viewed. can I use JS to do this automatically. Without having to type
by hand?
No, JS cannot access any of the files or directories it sits with on
the server.
I don't believe that. You can't get a directory listing, easily, but you
*do* have access to any file that is in the same domain as long as the
server doesn't prohibit access. If JS couldn't access them, AJAX would
be a totally dead technology.
These are different things. Yes, AJAX can acess files back at the
server, but it has to name them specifically. You can not scan a
directory and retrieve the listing with JS.
You probably can use an artifice,
if access to the folder is allowed you can try to open this folder in an
iframe or a popup, then to analyze links listed in this window via DOM
and to extract paths of images to display them somewhere.

OK it is not a livable way to do ... but it is possible.

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Jan 14 '07 #7

ASM wrote:
Benjamin a écrit :
Randy Webb wrote:
Benjamin said the following on 1/9/2007 10:10 PM:
mdh2...@gmail.com wrote:
I would like to put all my .jpg images in a folder into an array to be
viewed. can I use JS to do this automatically. Without having to type
by hand?
No, JS cannot access any of the files or directories it sits with on
the server.
I don't believe that. You can't get a directory listing, easily, but you
*do* have access to any file that is in the same domain as long as the
server doesn't prohibit access. If JS couldn't access them, AJAX would
be a totally dead technology.
These are different things. Yes, AJAX can acess files back at the
server, but it has to name them specifically. You can not scan a
directory and retrieve the listing with JS.

You probably can use an artifice,
if access to the folder is allowed you can try to open this folder in an
iframe or a popup, then to analyze links listed in this window via DOM
and to extract paths of images to display them somewhere.
This is counting on the server to list the contents of the directory if
there is no index file. Also, you would have to change your script for
every server.
>
OK it is not a livable way to do ... but it is possible.

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Jan 16 '07 #8
Benjamin wrote:
ASM wrote:
>Benjamin a écrit :
>>Randy Webb wrote:
Benjamin said the following on 1/9/2007 10:10 PM:
mdh2...@gmail.com wrote:
>I would like to put all my .jpg images in a folder into an array to be
>viewed. can I use JS to do this automatically. Without having to type
>by hand?
No, JS cannot access any of the files or directories it sits with on
the server.
I don't believe that. You can't get a directory listing, easily, but you
*do* have access to any file that is in the same domain as long as the
server doesn't prohibit access. If JS couldn't access them, AJAX would
be a totally dead technology.
These are different things. Yes, AJAX can acess files back at the
server, but it has to name them specifically. You can not scan a
directory and retrieve the listing with JS.
You probably can use an artifice,
if access to the folder is allowed you can try to open this folder in an
iframe or a popup, then to analyze links listed in this window via DOM
and to extract paths of images to display them somewhere.
This is counting on the server to list the contents of the directory if
there is no index file. Also, you would have to change your script for
every server.
>OK it is not a livable way to do ... but it is possible.

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Images on a remote server that you control should be trivial with PHP:

<?php
$localPath = '/usr/home/public_html/images';
$remotePath = 'http://yousite.com/images';
$fileList = '';

echo "<script language=\"JavaScript\" type=\"text/javascript\">\n";
echo "var remotePath = \"$remotePath\"";
echo "var imageFilenamesArr = new Array ("

if (is_dir($localPath)) {
if ($dh = opendir($localPath)) {
while (($file = readdir($dh)) !== false) {
$fileList .= "\"$file\",";
}
closedir($dh);
$fileList = substr($fileList, 0, strlen($fileList) - 1); // Remove the
final comma.
}
}
echo ");\n"
echo "</script>";
?>

That's just a draft, but the idea is that you can use PHP to generate your
JavaScript, and basically initialize variables that require some sort of data
from the server side environment. Its a simple, non-AJAXian solution to the
problem. If you're running 5.2.0, you could easily do this with JSON to, but
without the need to do complex XMLHttpRequest calls.

On a server-side file, you _shouldn't_ be able to access it directly with
JavaScript.
Jan 17 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: tmb | last post by:
I'm trying to use the Microsoft Search to search for a text string in a folder full of a bunch of ASP files. Seems like the normal "Search for text in files" program in XP Pro won't search...
2
by: Kiko + | last post by:
Hi, I've been getting this error: Server Error in '/applicationname' Application. ---------------------------------------------------------------------------- ---- Failed to create...
4
by: NH | last post by:
I know this isnt the correct forum but its is kinda related. Does anyone have any samples or links to some sample code that will poll a folder for new files. I am building an app which will keep...
7
by: johnny | last post by:
Any Good tools to create CSV Files? ReportLab only creates pdf files. I need something to create CSV files. Thank you.
1
by: toramadevi | last post by:
Hi ALL, I 'm using DevC++ for writing a C source code to create multiple files and folders under a directory.With the help of mkdir command i am able to get a bunch of 40 folders in the current...
0
by: raviranjan249 | last post by:
How to search for a particular string in a specific folder in all files throgh asp. If you have solution then pm to me <email removed>
4
by: Bob Bedford | last post by:
Hello, I've an array of array(1,2,3,4). I'd like to retrieve the values in 3 and 4 giving the values 1 and 2. How can I do that, how to search in an array of array ? in short, how to write the...
15
by: spazzo6281 | last post by:
Hello, is there a way to search a folder for certain files containing a wildcard or certain text entered into a text box. Right now all i can get is the whole list of files from a folder using the...
1
by: Claire | last post by:
Ive written a small string resource building utility that I send out to our translators. I have a setup project for each language we support, which picks out a group of 12 english resx files plus...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.